public class ThreadDemo12 {
    public static void main(String[] args) throws InterruptedException {

        MyThread6 myThread6 = new MyThread6(false);
        myThread6.start();

        // 通过属性控制线程
        Thread.sleep(3000);
        myThread6.isStop = true;
    }
}


class MyThread6 extends Thread {
    public boolean isStop;

    public MyThread6(boolean isStop) {
        this.isStop = isStop;
    }

    @Override
    public void run() {
        while (true) {
            if (!isStop) {
                System.out.println("新年快乐");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                System.out.println("保存数据");
                return;
            }
        }
    }
}
